<template>
<div>
  <br>
  <el-form :inline="true">
          <el-form-item label="归属表编号">
<el-input v-model="searchMap.table_id" placeholder="归属表编号"></el-input></el-form-item>
          <el-form-item label="列名称">
<el-input v-model="searchMap.column_name" placeholder="列名称"></el-input></el-form-item>
          <el-form-item label="列描述">
<el-input v-model="searchMap.column_comment" placeholder="列描述"></el-input></el-form-item>
          <el-form-item label="列类型">
<el-input v-model="searchMap.column_type" placeholder="列类型"></el-input></el-form-item>
          <el-form-item label="JAVA类型">
<el-input v-model="searchMap.java_type" placeholder="JAVA类型"></el-input></el-form-item>
          <el-form-item label="JAVA字段名">
<el-input v-model="searchMap.java_field" placeholder="JAVA字段名"></el-input></el-form-item>
          <el-form-item label="是否主键（1是）">
<el-input v-model="searchMap.is_pk" placeholder="是否主键（1是）"></el-input></el-form-item>
          <el-form-item label="是否自增（1是）">
<el-input v-model="searchMap.is_increment" placeholder="是否自增（1是）"></el-input></el-form-item>
          <el-form-item label="是否必填（1是）">
<el-input v-model="searchMap.is_required" placeholder="是否必填（1是）"></el-input></el-form-item>
          <el-form-item label="是否为插入字段（1是）">
<el-input v-model="searchMap.is_insert" placeholder="是否为插入字段（1是）"></el-input></el-form-item>
          <el-form-item label="是否编辑字段（1是）">
<el-input v-model="searchMap.is_edit" placeholder="是否编辑字段（1是）"></el-input></el-form-item>
          <el-form-item label="是否列表字段（1是）">
<el-input v-model="searchMap.is_list" placeholder="是否列表字段（1是）"></el-input></el-form-item>
          <el-form-item label="是否查询字段（1是）">
<el-input v-model="searchMap.is_query" placeholder="是否查询字段（1是）"></el-input></el-form-item>
          <el-form-item label="查询方式（等于、不等于、大于、小于、范围）">
<el-input v-model="searchMap.query_type" placeholder="查询方式（等于、不等于、大于、小于、范围）"></el-input></el-form-item>
          <el-form-item label="显示类型（文本框、文本域、下拉框、复选框、单选框、日期控件）">
<el-input v-model="searchMap.html_type" placeholder="显示类型（文本框、文本域、下拉框、复选框、单选框、日期控件）"></el-input></el-form-item>
          <el-form-item label="字典类型">
<el-input v-model="searchMap.dict_type" placeholder="字典类型"></el-input></el-form-item>
          <el-form-item label="排序">
<el-input v-model="searchMap.sort" placeholder="排序"></el-input></el-form-item>
          <el-form-item label="创建者">
<el-input v-model="searchMap.create_by" placeholder="创建者"></el-input></el-form-item>
          <el-form-item label="创建时间">
<el-input v-model="searchMap.create_time" placeholder="创建时间"></el-input></el-form-item>
          <el-form-item label="更新者">
<el-input v-model="searchMap.update_by" placeholder="更新者"></el-input></el-form-item>
          <el-form-item label="更新时间">
<el-input v-model="searchMap.update_time" placeholder="更新时间"></el-input></el-form-item>

    <el-button type="primary" @click="fetchData()">查询</el-button>
    <el-button type="primary" @click="handleEdit('')">新增</el-button>
  </el-form>
  <el-table
    :data="list"
    border
    style="width: 100%">
          <el-table-column prop="column_id" label="编号" width="80"></el-table-column>
          <el-table-column prop="table_id" label="归属表编号" width="80"></el-table-column>
          <el-table-column prop="column_name" label="列名称" width="80"></el-table-column>
          <el-table-column prop="column_comment" label="列描述" width="80"></el-table-column>
          <el-table-column prop="column_type" label="列类型" width="80"></el-table-column>
          <el-table-column prop="java_type" label="JAVA类型" width="80"></el-table-column>
          <el-table-column prop="java_field" label="JAVA字段名" width="80"></el-table-column>
          <el-table-column prop="is_pk" label="是否主键（1是）" width="80"></el-table-column>
          <el-table-column prop="is_increment" label="是否自增（1是）" width="80"></el-table-column>
          <el-table-column prop="is_required" label="是否必填（1是）" width="80"></el-table-column>
          <el-table-column prop="is_insert" label="是否为插入字段（1是）" width="80"></el-table-column>
          <el-table-column prop="is_edit" label="是否编辑字段（1是）" width="80"></el-table-column>
          <el-table-column prop="is_list" label="是否列表字段（1是）" width="80"></el-table-column>
          <el-table-column prop="is_query" label="是否查询字段（1是）" width="80"></el-table-column>
          <el-table-column prop="query_type" label="查询方式（等于、不等于、大于、小于、范围）" width="80"></el-table-column>
          <el-table-column prop="html_type" label="显示类型（文本框、文本域、下拉框、复选框、单选框、日期控件）" width="80"></el-table-column>
          <el-table-column prop="dict_type" label="字典类型" width="80"></el-table-column>
          <el-table-column prop="sort" label="排序" width="80"></el-table-column>
          <el-table-column prop="create_by" label="创建者" width="80"></el-table-column>
          <el-table-column prop="create_time" label="创建时间" width="80"></el-table-column>
          <el-table-column prop="update_by" label="更新者" width="80"></el-table-column>
          <el-table-column prop="update_time" label="更新时间" width="80"></el-table-column>

    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleEdit(scope.row.id)" type="text" size="small">修改</el-button>
        <el-button @click="handleDelete(scope.row.id)" type="text" size="small">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
      <el-pagination
      @size-change="fetchData"
      @current-change="fetchData"
      :current-page="currentPage"
      :page-sizes="[5,10,20]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>  
  <el-dialog title="编辑" :visible.sync="dialogFormVisible">
    <el-form label-width="80px">
        <el-form-item label="归属表编号"><el-input v-model="pojo.table_id"></el-input></el-form-item>
        <el-form-item label="列名称"><el-input v-model="pojo.column_name"></el-input></el-form-item>
        <el-form-item label="列描述"><el-input v-model="pojo.column_comment"></el-input></el-form-item>
        <el-form-item label="列类型"><el-input v-model="pojo.column_type"></el-input></el-form-item>
        <el-form-item label="JAVA类型"><el-input v-model="pojo.java_type"></el-input></el-form-item>
        <el-form-item label="JAVA字段名"><el-input v-model="pojo.java_field"></el-input></el-form-item>
        <el-form-item label="是否主键（1是）"><el-input v-model="pojo.is_pk"></el-input></el-form-item>
        <el-form-item label="是否自增（1是）"><el-input v-model="pojo.is_increment"></el-input></el-form-item>
        <el-form-item label="是否必填（1是）"><el-input v-model="pojo.is_required"></el-input></el-form-item>
        <el-form-item label="是否为插入字段（1是）"><el-input v-model="pojo.is_insert"></el-input></el-form-item>
        <el-form-item label="是否编辑字段（1是）"><el-input v-model="pojo.is_edit"></el-input></el-form-item>
        <el-form-item label="是否列表字段（1是）"><el-input v-model="pojo.is_list"></el-input></el-form-item>
        <el-form-item label="是否查询字段（1是）"><el-input v-model="pojo.is_query"></el-input></el-form-item>
        <el-form-item label="查询方式（等于、不等于、大于、小于、范围）"><el-input v-model="pojo.query_type"></el-input></el-form-item>
        <el-form-item label="显示类型（文本框、文本域、下拉框、复选框、单选框、日期控件）"><el-input v-model="pojo.html_type"></el-input></el-form-item>
        <el-form-item label="字典类型"><el-input v-model="pojo.dict_type"></el-input></el-form-item>
        <el-form-item label="排序"><el-input v-model="pojo.sort"></el-input></el-form-item>
        <el-form-item label="创建者"><el-input v-model="pojo.create_by"></el-input></el-form-item>
        <el-form-item label="创建时间"><el-input v-model="pojo.create_time"></el-input></el-form-item>
        <el-form-item label="更新者"><el-input v-model="pojo.update_by"></el-input></el-form-item>
        <el-form-item label="更新时间"><el-input v-model="pojo.update_time"></el-input></el-form-item>

        <el-button type="primary" @click="handleSave()">保存</el-button>
        <el-button @click="dialogFormVisible = false" >关闭</el-button>
    </el-form>
  </el-dialog>
</div>
</template>
<script>
import tableColumnApi from '@/api/tableColumn'
export default {
  data() {
    return {
      list: [],
      total: 0, // 总记录数
      currentPage: 1, // 当前页
      pageSize: 10, // 每页大小
      searchMap: {}, // 查询条件
      dialogFormVisible: false, // 编辑窗口是否可见
      pojo: {}, // 编辑表单绑定的实体对象
      cityList: [], // 城市列表
      id: '' // 当前用户修改的ID
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      tableColumnApi.search(this.currentPage, this.pageSize, this.searchMap).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
      })
    },
    handleSave() {
      tableColumnApi.update(this.id, this.pojo).then(response => {
        this.$message({
          message: response.message,
          type: (response.flag ? 'success' : 'error')
        })
        if (response.flag) { // 如果成功
          this.fetchData() // 刷新列表
        }
      })
      this.dialogFormVisible = false // 关闭窗口
    },
    handleEdit(id) {
      this.id = id
      this.dialogFormVisible = true // 打开窗口
      if (id !== '') { // 修改
        tableColumnApi.findById(id).then(response => {
          if (response.flag) {
            this.pojo = response.data
          }
        })
      } else {
        this.pojo = {} // 清空数据
      }
    },
    handleDelete(id) {
      this.$confirm('确定要删除此纪录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        tableColumnApi.deleteById(id).then(response => {
          this.$message({ message: response.message, type: (response.flag ? 'success' : 'error') })
          if (response.flag) {
            this.fetchData() // 刷新数据
          }
        })
      })
    }
  }
}
</script>
